package com.supermap.Attention.controller;

import com.supermap.Attention.service.AttentionService;
import com.supermap.attention.entity.Attention;
import com.supermap.common.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lxs
 * @Title:我的关注接口层
 * @Description:
 * @date 2018/2/27  14:56
 */
@Controller
@RequestMapping("AttentionrController")
public class AttentionController {
    /**
     * 使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(AttentionController.class);

    @Autowired
    private AttentionService attentionService;

    /**
     * 添加作物
     * @param request
     * @param attention
     * @return
     */
    @RequestMapping(value="addAttention")
    @ResponseBody
    public boolean addAttention(HttpServletRequest request,Attention attention) {
        //获取登录人的用户名
        String loginName = request.getParameter("loginName");
        int userid=attentionService.getUserIdByuserName(loginName);
        attention.setUserid(userid);
        return attentionService.saveAttention(attention);
    }

    /**
     * 我的关注
     * @param request
     * @return
     */
    @RequestMapping(value="getAttentionsList")
    @ResponseBody
    public JSONUtil getAttentionsList(HttpServletRequest request) {
        //获取登录人的用户名
        String loginName = request.getParameter("loginName");
        int userid=attentionService.getUserIdByuserName(loginName);
        return attentionService.getAttentionsByUserId(userid);
    }

    /**
     * 根据作物id删除  作物
     * @param request
     * @return
     */
    @RequestMapping(value="deleteByCropId")
    @ResponseBody
    public boolean deleteByCropId(HttpServletRequest request){
       String id = request.getParameter("id");
        return attentionService.deleteByCropId(Integer.valueOf(id));
    }

    /**
     * 修改作物
     * @param request
     * @return
     */
    @RequestMapping(value="updateAttentionById")
    @ResponseBody
    public boolean updateAttentionById(HttpServletRequest request,Attention attention){

       return  attentionService.updateAttentionById(attention);
    }

}



